package com.hf.security

import com.hf.constant.OrderLunchConst
import com.hf.date.DateUtils
import com.hf.mail.AbstractMailService
import com.hf.mail.MailMessage
import com.hf.mail.MailSenderService
import com.hf.template.GspTemplateUtils

class MailOweMoneyReminderService extends AbstractMailService {

	OrderUserService orderUserService

	@Override
	public void sendMail() {
		List<OrderUser> orderUserList = orderUserService.getOweMoneyUserNotPaid()
		send(orderUserList)
	}

	private void send(List<OrderUser> orderUserList) {
		MailMessage mail = new MailMessage()

		if(OrderLunchConst.IS_TEST) {
			mail.to << OrderLunchConst.ADMIN_EMAIL
		} else {
			orderUserList.each { OrderUser user ->
				mail.to << user.email
			}
		}
		mail.Cc << OrderLunchConst.ADMIN_EMAIL

		mail.subject = OrderLunchConst.FROM_ORDER_LUNCH + "Reminder: There ain't no such thing as a free lunch.   " + DateUtils.getPeriodStartEndDayString()

		mail.htmlText = GspTemplateUtils.renderTemplate('/bill/emailOweMoneyReminder', [orderUserList : orderUserList])

		mailSenderService.sendAsyn(mail)
	}
}
